# -*- coding: utf-8 -*-


import os
import uuid
import django
from datetime import datetime
from core.initialize import Initialize
from apps.sys.models import Menu, DictType, DictData

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
django.setup()


class Init(Initialize):

    def init_dict(self):
        dict_type = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "字段类型",
                "type": "rms_field_type",
                "remark": "字段类型"
            }
        ]
        dict_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 1,
                "label": "BIGINT",
                "value": "BIGINT",
                "tagType": "primary",
                "tagClass": "",
                "remark": "BIGINT"
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 2,
                "label": "BOOLEAN",
                "value": "BOOLEAN",
                "tagType": "primary",
                "tagClass": "",
                "remark": "BOOLEAN"
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 3,
                "label": "FLOAT",
                "value": "FLOAT",
                "tagType": "primary",
                "tagClass": "",
                "remark": "FLOAT"
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 4,
                "label": "INT",
                "value": "INT",
                "tagType": "primary",
                "tagClass": "",
                "remark": "INT"
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 5,
                "label": "IPV4",
                "value": "IPV4",
                "tagType": "primary",
                "tagClass": "",
                "remark": "IPV4"
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 6,
                "label": "IPV6",
                "value": "IPV6",
                "tagType": "primary",
                "tagClass": "",
                "remark": "IPV6"
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 7,
                "label": "TIMESTAMP",
                "value": "TIMESTAMP",
                "tagType": "primary",
                "tagClass": "",
                "remark": "TIMESTAMP"
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "rms_field_type",
                "sort": 8,
                "label": "VARCHAR",
                "value": "VARCHAR",
                "tagType": "primary",
                "tagClass": "",
                "remark": "VARCHAR"
            }
        ]
        self.save(DictType, dict_type, "字典类型")
        self.save(DictData, dict_data, "字典数据")

    def init_menu(self):
        """
        初始化菜单表-资源管理
        """
        rms = uuid.uuid4()
        rms_protocol = uuid.uuid4()
        rms_packet = uuid.uuid4()
        rms_interface = uuid.uuid4()
        self.menu_rms_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": rms,
                "name": "资源管理",
                "type": "M",
                "icon": "resource",
                "path": "/rms",
                "component": "Layout",
                "perms": None,
                "nesting": True,
                "redirect": "noRedirect",
                "parent_id": None,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": rms_protocol,
                "name": "协议管理",
                "type": "C",
                "icon": "protocol",
                "path": "protocol",
                "component": "rms/protocol/index",
                "perms": "rms:protocol:list",
                "parent_id": rms,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "协议查询",
                "type": "F",
                "icon": "#",
                "perms": "rms:protocol:query",
                "parent_id": rms_protocol,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "协议新增",
                "type": "F",
                "icon": "#",
                "perms": "rms:protocol:add",
                "parent_id": rms_protocol,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "协议修改",
                "type": "F",
                "icon": "#",
                "perms": "rms:protocol:edit",
                "parent_id": rms_protocol,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "协议删除",
                "type": "F",
                "icon": "#",
                "perms": "rms:protocol:delete",
                "parent_id": rms_protocol,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "协议导入",
                "type": "F",
                "icon": "#",
                "perms": "rms:protocol:import",
                "parent_id": rms_protocol,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "协议导出",
                "type": "F",
                "icon": "#",
                "perms": "rms:protocol:export",
                "parent_id": rms_protocol,
                "sort": 6,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": rms_packet,
                "name": "报文管理",
                "type": "C",
                "icon": "packet",
                "path": "packet",
                "component": "rms/packet/index",
                "perms": "rms:packet:list",
                "parent_id": rms,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "报文查询",
                "type": "F",
                "icon": "#",
                "perms": "rms:packet:query",
                "parent_id": rms_packet,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "报文新增",
                "type": "F",
                "icon": "#",
                "perms": "rms:packet:add",
                "parent_id": rms_packet,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "报文修改",
                "type": "F",
                "icon": "#",
                "perms": "rms:packet:edit",
                "parent_id": rms_packet,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "报文删除",
                "type": "F",
                "icon": "#",
                "perms": "rms:packet:delete",
                "parent_id": rms_packet,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "报文导入",
                "type": "F",
                "icon": "#",
                "perms": "rms:packet:import",
                "parent_id": rms_packet,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "报文导出",
                "type": "F",
                "icon": "#",
                "perms": "rms:packet:export",
                "parent_id": rms_packet,
                "sort": 6,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": rms_interface,
                "name": "接口管理",
                "type": "C",
                "icon": "interface",
                "path": "interface",
                "component": "rms/interface/index",
                "perms": "rms:interface:list",
                "parent_id": rms,
                "sort": 3,
            }, {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "接口查询",
                "type": "F",
                "icon": "#",
                "perms": "rms:interface:query",
                "parent_id": rms_interface,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "接口新增",
                "type": "F",
                "icon": "#",
                "perms": "rms:interface:add",
                "parent_id": rms_interface,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "接口修改",
                "type": "F",
                "icon": "#",
                "perms": "rms:interface:edit",
                "parent_id": rms_interface,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "接口删除",
                "type": "F",
                "icon": "#",
                "perms": "rms:interface:delete",
                "parent_id": rms_interface,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "接口导入",
                "type": "F",
                "icon": "#",
                "perms": "rms:interface:import",
                "parent_id": rms_interface,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "接口导出",
                "type": "F",
                "icon": "#",
                "perms": "rms:interface:export",
                "parent_id": rms_interface,
                "sort": 6,
            },
        ]
        self.save(Menu, self.menu_rms_data, "菜单表")

    def run(self):
        self.init_dict()
        self.init_menu()


def main(reset=False):
    Init(reset).run()
    pass


if __name__ == '__main__':
    main()
